import 'dart:convert' show json;

T asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class MessageType {
  MessageType({
    this.type,
    this.msg,
  });

  factory MessageType.fromJson(Map<String, dynamic> jsonRes) => jsonRes == null
      ? null
      : MessageType(
          type: asT<int>(jsonRes['type']),
          msg: asT<String>(jsonRes['msg']),
        );

  int type;
  String msg;

  Map<String, dynamic> toJson() => <String, dynamic>{
        'type': type,
        'msg': msg,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
